<#include "../base.ftl"/>

<#macro title>
物流交易系统
</#macro>
<#macro jsscript>
var currentData;		  //数据源
var items_per_page = 10;  //一页显示多少条
var callBackRef = 0;	  //回调函数选择
var urlIndex = '${Parameters.ref}';			  //url地址选择
var url;
$(function(){
	SwitchMenu(urlIndex);
});
  //物流供应搜索参数
  var transport;
  var options;
  var cmbCity;
  var select2;
  var arriveTime;
   transport=decodeURI('${Parameters.transport!""}');
   options=decodeURI('${Parameters.option!""}');
   cmbCity=decodeURI('${Parameters.cmbCity!""}');
   select2=decodeURI('${Parameters.select2!""}');
   arriveTime=decodeURI('${Parameters.arriveTime!""}');
   //仓储供应搜索参数
   var optionn;
   var city;
   var city1;
   var arriveDate;
   var storageTransport;
   storageTransport=decodeURI('${Parameters.storageTransport!""}');
   optionn=decodeURI('${Parameters.optionn!""}');
   city=decodeURI('${Parameters.city!""}');
   city1=decodeURI('${Parameters.city1!""}');
   arriveDate=decodeURI('${Parameters.arriveDate!""}');
	//var   td= '<%=Request.Querystring( "id ")%>' 
	// var id= window.location.toString().getQuery('ID');
$("#class1").ready(function(){
function SwitchMenu(urlIndex){
	if(urlIndex ==1){
		$("#menu > li > a").removeClass("menu-active")
		$('#logisticsSupplyMsg').addClass("menu-active");
		getColor(); 
		url= '${request.contextPath}/list/classify/TltLogisticsSupply/list.html';
	} 
	if(urlIndex == 2) {
		$("#menu > li > a").removeClass("menu-active")
		$('#logisticsDemandMsg').addClass("menu-active");
		getColor(); 
		url= '${request.contextPath}/list/classify/TltLogisticsDemand/list.html';
	} 
	if(urlIndex == 3) {
		$("#menu > li > a").removeClass("menu-active")
		$('#storageSupplyMsg').addClass("menu-active");
		getColor(); 
		url= '${request.contextPath}/list/classify/TltStorageSupply/list.html';
	} 
	if(urlIndex == 4) {
		$("#menu > li > a").removeClass("menu-active")
		$('#storageDemandMsg').addClass("menu-active");
		getColor(); 
		url= '${request.contextPath}/list/classify/TltStorageDemand/list.html';
	}
	$("#class1").ready(function(){
		$.ajax({
			url: url,
			type:'post',
            data:{"_search":true,"filters":'{"groupOp":"AND","rules":[{"field":"TRANSPORT_MODE","op":"eq","data":3333}]'},
			data: {},
			dataType: 'json',
			success:function(data){
				currentData = data;
				setPage(data);
			}
		});
	});
	
}

function setPage(data){
	
	var optInit = getOptionsFromForm();
//    alert(data.page.totalCount);
    $("#Pagination").pagination(data.page.totalCount, optInit);
	/*$.map(data.result[0],function(key,value){
			console.log(key+"="+value);
			$("#"+value.toLocaleLowerCase()).html(key);
		});*/
}

function pageselectCallback(page_index, jq){

    var max_elem = Math.min((page_index+1) * items_per_page, currentData.page.totalCount);
    var newcontent = '';

    var currRows = Math.min(items_per_page,currentData.page.totalCount - (page_index * items_per_page));
    // Iterate through a selection of the content and build an HTML string
    //alert((page_index+1) +"="+items_per_page);
    $.ajax({
		url: url,
		type:'post',
		data: {"page.pageNo":page_index+1,"page.pageSize":items_per_page},
		dataType: 'json',
		success:function(data){
			currentData = data;
				getAllData(currRows);
		}
    });

    // Replace old content with new content
    $('#class1').html(newcontent);

    // Prevent click eventpropagation
    return false;
};


function pageselectSearchCallback(page_index, jq){     //搜索按钮回调函数

    var max_elem = Math.min((page_index+1) * items_per_page, currentData.page.totalCount);
    var currRows = Math.min(items_per_page,currentData.page.totalCount - (page_index * items_per_page));
    var newcontent = '';

    // Iterate through a selection of the content and build an HTML string
    //alert((page_index+1) +"="+items_per_page);
    var yunshu = jQuery('#yunshufangshi').val();
	var qiyun = jQuery('#qiyundi').val();
	var mudi = jQuery('#mudidi').val();
    $.ajax({
		url: url,
		type:'post',
		data: {"_search":true,"filters":'{"groupOp":"AND","rules":[{"field":"TRANSPORT_MODE","op":"eq","data":"'+yunshu+'"},{"field":"CURRENT_ADDRESS","op":"eq","data":"'+qiyun+'"},{"field":"PLAN_DESTINATION","op":"eq","data":"'+mudi+'"}]}',"page.pageNo":page_index+1,"page.pageSize":items_per_page},
		dataType: 'json',
		success:function(data){
			currentData = data;
			//var currPageSize = (currentData.page.totalCount - (page_index -1) * items_per_page);
			
			
			
			getAllData(currRows);
		}
    });

    // Replace old content with new content
    $('#class1').html(newcontent);

    // Prevent click eventpropagation
    return false;
};

function getAllData(currRows){
	if(urlIndex == 1){
		for(var i=0;i<currRows;i++){
		$("#class1").append("<tr><td>" + "运输方式：" + currentData.page.result[i].TRANSPORT_MODE + "</td>" + "<td>" + "运输资质：" + currentData.page.result[i].TRANSPORT_QUALIFICATION +"</td>" + "<td>" + "起运地：" + currentData.page.result[i].CURRENT_ADDRESS + "</td>" +"<td>" + "目的地：" + currentData.page.result[i].PLAN_DESTINATION + "</td>" + "<td>" + "可载重量：" + currentData.page.result[i].MAX_LOAD_WEIGHT + "</td>" +"<td>" + "可载体积：" + currentData.page.result[i].MAX_LOAD_VOLUME + "</td>" + "<td>" + "预计到达日期：" + currentData.page.result[i].ARRIVE_DATE + "</td></tr>");
		}
	} else if (urlIndex == 2){
		for(var i=0;i<currRows;i++){
			$("#class1").append("<tr><td>" + "运输方式：" + currentData.page.result[i].TRANSPORT_MODE + "</td>" + "<td>" + "货物类别：" + currentData.page.result[i].CARGO_TYPE +"</td>" + "<td>" + "重量：" + currentData.page.result[i].CARGO_WEIGHT + "</td>" +"<td>" + "体积：" + currentData.page.result[i].CARGO_VOLUME + "</td>" + "<td>" + "起运地：" + currentData.page.result[i].DISPATCH_ADDRESS + "</td>" +"<td>" + "目的地：" + currentData.page.result[i].DESTINATION + "</td>" + "<td>" + "预计到达日期：" + currentData.page.result[i].ARRIVE_DATE + "</td></tr>");
		}
	} else if(urlIndex == 3) {
		for(var i=0;i<currRows;i++){
			$("#class1").append("<tr><td>" + "仓库地址：" + currentData.page.result[i].WAREHOUSE_ADDRESS + "</td>" + "<td>" + "仓库资质：" + currentData.page.result[i].WAREHOUSE_QUALIFICATION +"</td>" + "<td>" + "要求租用最短时间(天)：" + currentData.page.result[i].MIN_RENT_DAY + "</td>" +"<td>" + "离最近水运码头距离：" + currentData.page.result[i].DOCK_DISTANCE + "</td></tr>");
		}
	} else if(urlIndex == 4){
		for(var i=0;i<currRows;i++){
			$("#class1").append("<tr><td>" + "货物所在地：" + currentData.page.result[i].CARGO_ADDRESS + "</td>" + "<td>" + "货物类型：" + currentData.page.result[i].CARGO_TYPE +"</td>" + "<td>" + "重量：" + currentData.page.result[i].CARGO_WEIGHT + "</td>" +"<td>" + "体积：" + currentData.page.result[i].CARGO_VOLUME + "<td>" + "预计入库时间：" + currentData.page.result[i].ENTRY_DATE + "</td>" + "<td>" +"预计出库时间：" + currentData.page.result[i].DELIVERY_DATE + "</td></tr>");
		}
	}
	return;
}

function getOptionsFromForm(){
    var opt = {callback: pageselectCallback};
    // Collect options from the text fields - the fields are named like their option counterparts
    $("input:text").each(function(){
        opt[this.name] = this.className.match(/numeric/) ? parseInt(this.value) : this.value;
    });
    // Avoid html injections in this demo
    var htmlspecialchars ={ "&":"&amp;", "<":"&lt;", ">":"&gt;", '"':"&quot;"}
    $.each(htmlspecialchars, function(k,v){
        opt.prev_text = opt.prev_text.replace(k,v);
        opt.next_text = opt.next_text.replace(k,v);
    })
    return opt;
};

function Go() {
	//var opt = {callback: pageselectCallback};
	
	
	
    var pagenum = jQuery('#pages').val();
    var Part = new RegExp("^[0-9]+");
    var pages = Math.floor(currentData.page.totalCount / items_per_page);
    var realPages = pages== 0?pages:pages+1;
    if (!Part.exec(pagenum)) {
        alert("输入格式错误!");
        return;
    }
    
    else if (pagenum > realPages) {
    	alert("请输入在总页数范围内的页数!");
    	return;
    }
	
    if(callBackRef == 0){
    	$("#Pagination").pagination(currentData.page.totalCount, {  
            'items_per_page'      : 10,  
            'num_display_entries' : 10,  
            'num_edge_entries'    : 2,  
            'current_page'		  : pagenum -1,
            'prev_text'           : "上一页",  
            'next_text'           : "下一页",  
            'callback'            : pageselectCallback  
        }); 
    }else if(callBackRef == 1){
    	$("#Pagination").pagination(currentData.page.totalCount, {  
            'items_per_page'      : 10,  
            'num_display_entries' : 10,  
            'num_edge_entries'    : 2,  
            'current_page'		  : pagenum -1,
            'prev_text'           : "上一页",  
            'next_text'           : "下一页",  
            'callback'            : pageselectSearchCallback  
        }); 
    }
    jQuery('#pages').empty();
}

function selectInfo(){
	callBackRef = 1;
	var yunshu = jQuery('#yunshufangshi').val();
	var qiyun = jQuery('#qiyundi').val();
	var mudi = jQuery('#mudidi').val();
    $.ajax({
    	url: url,
		type:'post',
		data: {"_search":true,"filters":'{"groupOp":"AND","rules":[{"field":"TRANSPORT_MODE","op":"eq","data":"'+yunshu+'"},{"field":"CURRENT_ADDRESS","op":"eq","data":"'+qiyun+'"},{"field":"PLAN_DESTINATION","op":"eq","data":"'+mudi+'"}]}',"page.pageNo":"1","page.pageSize":"10"},
		dataType: 'json',
		success:function(data){
			currentData = data;
			//
			//$("#Pagination").pagination(data.page.totalCount, optInit);
			
			//setPage(data);
			
			$("#Pagination").pagination(data.page.totalCount, {  
		        'items_per_page'      : 10,  
		        'num_display_entries' : 10,  
		        'num_edge_entries'    : 2,  
		        'current_page'		  : 0,
		        'prev_text'           : "上一页",  
		        'next_text'           : "下一页",
		        'callback'            : pageselectSearchCallback
		    });  
			
			 $("#class1").empty();
		    /*for(var i=0;i<10;i++)
			{
				$("#class1").append("<tr><td>" + "运输方式：" + currentData.page.result[i].TRANSPORT_MODE + 

"</td>" + "<td>" + "运输资质：" + 
						currentData.page.result[i].TRANSPORT_QUALIFICATION +"</td>" + "<td>" + "可

载重量：" + currentData.page.result[i].MAX_LOAD_WEIGHT + "</td>" +
						"<td>" + "可载体积：" + currentData.page.result[i].MAX_LOAD_VOLUME + 

"</td>" + "<td>" + "预计到达日期：" + currentData.page.result[i].ARRIVE_DATE + "</td></tr>");
			}*/
		}
    });
}

function getColor(){
//	var color1 = jQuery('#logisticsSupplyMsg').val();
//	var color2 = jQuery('#logisticsDemandMsg').val();
//	var color3 = jQuery('#storageSupplyMsg').val();
//	var color4 = jQuery('#storageDemandMsg').val();
	$('#logisticsSupplyMsg').click(function(){
		$("#menu > li > a").removeClass("menu-active")
		$('#logisticsSupplyMsg').addClass("menu-active");
		url= '${request.contextPath}/list/classify/TltLogisticsSupply/list.html';
		urlIndex =1;
		$.ajax({
			url: "${request.contextPath}/list/classify/TltLogisticsSupply/list.html",
			type:'post',
			data: {},
			dataType: 'json',
			success:function(data){
				currentData = data;
				//setPage(data);
				$("#Pagination").pagination(data.page.totalCount, {  
			        'items_per_page'      : 10,  
			        'num_display_entries' : 10,  
			        'num_edge_entries'    : 2,  
			        'current_page'		  : 0,
			        'prev_text'           : "上一页",  
			        'next_text'           : "下一页",
			        'callback'            : pageselectCallback
			    });  
				 $("#class1").empty();
			}
		});
	});
	$('#logisticsDemandMsg').click(function(){
	
	
}
</#macro>
<#macro main>
	<div id="main">
    	<div class="span2">
            <ul class="nav nav-list bs-docs-sidenav affix-top" id="menu">
              <li><a id="logisticsSupplyMsg"><i class="icon-chevron-right"></i>物流供应信息</a></li>
              <li><a id="logisticsDemandMsg"><i class="icon-chevron-right"></i>物流需求信息</a></li>
              <li><a id="storageSupplyMsg"><i class="icon-chevron-right"></i>仓储供应信息</a></li>
              <li><a id="storageDemandMsg"><i class="icon-chevron-right"></i>仓储需求信息</a></li>
            </ul>
            <ul class="nav bs-docs-sidenav affix-top">
            <li><i class="icon-chevron-right"></i>快速搜索</li>
	            <tr><label>运输方式：</label><input type="text" id="yunshufangshi" class="input-mini input-primary" /></tr>
	            <tr><label>起运地：</label><input type="text" id="qiyundi" class="input-mini input-primary" /></tr>
	            <tr><label>目的地：</label><input type="text" id="mudidi" class="input-mini input-primary" /></tr>
	            <tr><input type="button" id="select" value="搜索"  onclick="selectInfo()"></tr>
          </ul>
        </div>
        
        <div id="span10" class="span10" >
        	<table id="class1" class="table table-bordered table-hover table-condensed">
        	
	        </table>
        </div>
        <div style="margin-left:500px;">
			<div id="Pagination" class="pagination" style="margin-top: 20px;">
		    	<table id="class2" class="table table-bordered table-hover table-condensed" style="display:none">
					<label for="prev_text"></label><input type="text" value="上一页" name="prev_text" id="prev_text"/>
				    <label for="next_text"><input type="text" value="下一页" name="next_text" id="next_text"/>
		        </table>
		    </div>
	        <input type="text" class="input-mini input-primary" name="pages" id="pages" />
	        <input type="button" value="Go" onclick="Go()" style="margin-bottom: 5px;margin-right: 5px;padding: 0.3em 0.5em"/>
        </div>
   	</div>
</#macro>